<template>
  <input type="text" placeholder="请输入待办事项" @keyup.enter="add" v-model="text">
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      text: ""
    }
  },
  props:{
    addTodo:{
      type:Function,
      required:true
    }
  }
  ,
  methods: {
    add() {

      const text = this.text.trim()
      if (!text) {
        alert("输入内容不能为空")
      } else {
        let todo = {"text": text, "finished": false}
        console.log(todo)
        this.addTodo(todo)
      }
      this.text = ""


    }
  }
}
</script>

<style scoped>

</style>